import { NetWorkService } from "../../apiNetworkServices"

export type RoomState = {
  locationId: string
  body: {
    start_time: string
    end_time: string
    selected_dates: any[]
    provider: string
  }
}

export type RoomCostState = {
  location: string
  room: string
}

/**
 * Network request used to fetch ethera locations
 * @returns the response ethera locations
 */

const getEtheraLocations = () => {
  return new Promise((resolve, reject) => {
    NetWorkService.Get({
      url: `/api/e-location`,
    })
      .then((res) => {
        resolve(res)
      })
      .catch((error) => reject(error))
  })
}

/**
 * Network request used to fetch other  locations
 * @returns the response containing other  locations
 */

const getOtherLocations = (providerId: string) => {
  return new Promise((resolve, reject) => {
    NetWorkService.Get({
      url: `/api/providers/${providerId}/provider-location`,
    })
      .then((res) => {
        resolve(res)
      })
      .catch((error) => reject(error))
  })
}

/**
 * Network request used to fetch rooms
 * @returns the response containing room list
 */

//TODO make params?.body dynamic
const getEtheraRooms = (params: RoomState) => {
  return new Promise((resolve, reject) => {
    NetWorkService.Post({
      url: `/api/locations/${params?.locationId}/valid-rooms-list`,
      body: params?.body,
    })
      .then((res) => {
        resolve(res)
      })
      .catch((error) => reject(error))
  })
}

/**
 * Network request used to fetch rooms
 * @returns the response containing room list
 */

//TODO make params?.body dynamic
const getRoomCost = (body: RoomCostState) => {
  return new Promise((resolve, reject) => {
    NetWorkService.Post({
      url: `api/providers/tiers/my-tier`,
      body,
    })
      .then((res) => {
        resolve(res)
      })
      .catch((error) => reject(error))
  })
}
export { getEtheraLocations, getOtherLocations, getEtheraRooms, getRoomCost }
